<?php

  //connect to database
  @connectToDb($dbServer, $dbAll, $dbAllPW, $dbName);

  function insertProblem($staff_no, $enquiry_date, $prod_no, $description, $quantity, $reason, $dep_no, $customer_no)
  {

    $result = mysql_query("SELECT count(*) FROM customer_enquiry_problem")or die ('Error: '.mysql_error ());
    $row = mysql_fetch_row($result)or die ('Error: '.mysql_error ());
    $id = $row[0] + 1;

    if(mysql_query("INSERT INTO customer_enquiry_problem VALUES(" . $id . ", " . $staff_no . ", '" . $enquiry_date . "', " . $prod_no . ", '" . $description . "', " . $quantity . ", '" . $reason . "', " . $dep_no . ", " . $customer_no . ")"))
	{
      return true;
	}
    else
    {
      return false;
    }

	mysql_close();
  }

  function checkValidProductNo($prod_no)
  {
	  $sql = "SELECT * FROM product WHERE prod_no = '" . $prod_no . "'";
      $sql_result = @mysql_query($sql);
      $sql_num = @mysql_numrows($sql_result);

      if($sql_num == 0)
      {
        return false;
      }
      else
      {
        return true;
      }
  }

  function checkValidCustomerNo($customer_no)
  {
	  $sql = "SELECT * FROM customer WHERE customer_no = '" . $customer_no . "'";
      $sql_result = @mysql_query($sql);
      $sql_num = @mysql_numrows($sql_result);

      if($sql_num == 0)
      {
        return false;
      }
      else
      {
        return true;
      }
  }
 
  function checkValidStaffNo($staff_no)
  {
	  $sql = "SELECT * FROM staff WHERE staff_no = '" . $staff_no . "'";
      $sql_result = @mysql_query($sql);
      $sql_num = @mysql_numrows($sql_result);

      if($sql_num == 0)
      {
        return false;
      }
      else
      {
        return true;
      }
  }
?>